package com.java1412.controller;

import com.java1412.entity.OrderForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author java1412
 * @create 2021-05-18 16:40
 */
@Slf4j
@RestController
public class BindController {

    @PostMapping(value = "/order")
    public String order(@Valid @RequestBody OrderForm form, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return bindingResult.getFieldError().getDefaultMessage();
        }
        log.warn("order={}", form.toString());
        return "success";
    }
}
